package com.hc.homestay.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hc.homestay.commons.ResultMap;
import com.hc.homestay.pojo.ToStaff;
import com.hc.homestay.service.ToStaffService;


 
@Controller
@RequestMapping("/toSalff")
public class ToSalffController {

	@Autowired
	private ToStaffService toStaffService;

	
	
	@RequestMapping("/test")
	@ResponseBody
	public String findToSalffTest(String name){
		return "红红火火恍恍惚惚或或或或或或或或";
	}
	
	
	
	@RequestMapping("/list")
	@ResponseBody
	public ResultMap<ToStaff> findToSalffList(@RequestParam  Map<String,Object> map){
		return toStaffService.findToStaffList(map); 
	}
	
	
	
	@RequestMapping("/delete")
	@ResponseBody
	public Integer deleteToStaffByid(Integer id) {
		return toStaffService.deleteToStaffByid(id);
	}
	
	
	@RequestMapping("/update")
	@ResponseBody
	public Integer updateToStaff(@RequestBody ToStaff toStaff) {
		return toStaffService.updatetoSalff(toStaff);
	}
	
	@ResponseBody
	@RequestMapping("/toLogin")
	public Integer getLogin( String sName, String sPwd, HttpServletRequest request) {
		ToStaff toStaff = new ToStaff();
		toStaff.setsName(sName);
		toStaff.setsPwd(sPwd);
		ToStaff login = toStaffService.getLogin(toStaff);
		if (login != null) {
			request.getSession().setAttribute("toStaff", login);
			return 1;
		} else {
			return 0;
		}
	}
	
	@ResponseBody
	@RequestMapping("/getToStaff")
	public Object getToStaff(HttpServletRequest request) {
		return request.getSession().getAttribute("toStaff");
	}
	
	
	
	
	
}

